# _*_ coding: utf-8 _*_
"""
    惯性导航软件平台
"""

import socket
import sSerial
import locProtocol

import opQue
HOST = ''
PORT = 6666
BUFSIZE = 1024
ADDR = (HOST, PORT)


def connect(queue):
    tcpSerSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # 创建套头字
    tcpSerSock.bind(ADDR)   # 套接字与地址绑定
    tcpSerSock.listen(5)    # 监听连接
    while True:
        print('waiting for connection...')
        tcpCliSock, addrs = tcpSerSock.accept()
        print('....connected from:', addrs)

        while True:
            # 从队列2中读取流数据
            data = opQue.readQ(queue=queue)
            if data is not None:
                try:
                    tcpCliSock.send(data)
                except socket.error:
                    print('socket error')
                    break
            else:
                print('error data')
    tcpCliSock.close()